package datamining.sequence;

import datamining.algorithms.prefixspan.PThreadEnvironment;
import datamining.miner.enviroment.ThreadEnvironment;

/** 
 * <p>
 * 创建于 2012-12-8 上午9:56:57
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * <br>
 * Copyright 2012 xujinghu
 * <br>
 * Lisence: Apache
 */
public class IndexedItem<ItemType> implements Comparable<IndexedItem<ItemType>>{

	public final int itemSetIndex;//item所属集合的index
	public final int itemIndex;//item在集合内的index
	public IndexedItem<ItemType> next = null;
	
	public final ItemType label;//item的标签
	
	public IndexedItem(int itemSetIndex, int itemIndex, ItemType label){
		this.itemSetIndex = itemSetIndex;
		this.itemIndex = itemIndex;
		this.label = label;
	}
	
	public void release(ThreadEnvironment<ItemType> target){
		target.push(this);
	}

	/* 
	 * 按照先坐标、后标签自然序的顺序比较
	 */
	@Override
	public int compareTo(IndexedItem<ItemType> o) {
		int diff = 0;
		diff = itemSetIndex - o.itemSetIndex;
		if(diff != 0)
			return diff;
		diff = this.itemIndex - o.itemIndex;
		if(diff != 0)
			return diff;
		diff = ((Comparable)label).compareTo(o.label);
		if(diff != 0)
			return diff;
		return 0;
	}
	
	public String toString(){
		return "［" +itemSetIndex + "，" +  itemIndex + "，" + label + "］";
	}
}
